<template>
    <div id="News">
        <body-container>
            <section slot="features">
                <el-button @click="dialog.open()">新增</el-button>
            </section>
            <vj-table :page-obj="pageObj" @loadTable="onSearch" :loading="loading" :cfg-list="cfgList"
                      :table-data="tableData">
                <template #action="row">
                    <text-button text="编辑" @click="dialog.open(row)"/>
                    <text-button text="删除" @click="del(row.id)"/>
                </template>
            </vj-table>
        </body-container>
        <news-dialog @refresh="onSearch" ref="dialog"/>
    </div>
</template>
<script lang="ts">
    import Vue, {ComponentOptions, VueConstructor} from "vue"
    import Component from 'vue-class-component'
    import BodyContainer from "@/components/layout/body-container.vue";
    import SearchFormContainer from "@/components/layout/search-form-conatiner.vue";
    import {Mixins, Ref} from "vue-property-decorator";
    import {TableMixin} from "@/plugins/mixins/table";
    import {requestByDelete, requestByGet, requestByPost} from "@/utils/request";
    import {formatOptions, groupBy, hookLoading, itemFromArr, updateCfgOption} from "vijay-util";
    import TextButton from "@/components/basic/text-button.vue";
    import {NewsTB, PuzzleRecordTB} from "@/config/table";
    import {PuzzleRecordSH} from "@/config/search";
    import NewsDialog from "@/components/dialog/news-dialog.vue";
    import {warnConfirm} from "@/utils/logic";

    export const title = "news";
    @Component({
        components: {NewsDialog, TextButton, SearchFormContainer, BodyContainer}
    })
    export default class News extends Mixins(TableMixin) implements ComponentOptions<Vue> {
        name = "News"
        cfgList = NewsTB;
        @Ref()dialog!:any;
        @hookLoading()
        async onSearch(pageNo?, pageSize?) {
          const params = Object.assign({pageNo, pageSize}, this.selectForm, this.searchForm);
          const res = await requestByGet(`qqc/qqcNews/list`, params);
          this.tableData = res.records;
          return res;
        }

      async del(id) {
        await warnConfirm();
        await requestByDelete(`qqc/qqcNews/delete`, {id});
        this.$message.success("操作成功！");
        return this.onSearch();
      }
        created() {
            this.onSearch();
        }
    }
</script>

<style scoped lang="scss">
    @import "~assets/common.scss";
    @import "~assets/scss/variables.scss";
    #News {
    }
</style>
